'''
Created on Feb 18, 2013

@author: melegy
'''
import sys
sys.path.append("../")
import os
import logging
import logging.handlers
import datetime
#===============================================================================
path=os.path.dirname(os.path.abspath(__file__))
#===============================================================================
# this is the Main Logger
#===============================================================================
loggers=dict()
def getLogger(logger):
    formatter = logging.Formatter('%(asctime)s %(message)s')
    logging.basicConfig(level=logging.DEBUG)
    try:
        log=loggers[logger]
        return log
    except:
        pass
    log = logging.getLogger(logger)
    efh =  logging.handlers.RotatingFileHandler(path+"/"+logger+'_error.log', maxBytes=10000000, backupCount=5)
    dfh = logging.handlers.RotatingFileHandler(path+"/"+logger+'_debug.log', maxBytes=10000000, backupCount=5)
    ifh = logging.handlers.RotatingFileHandler(path+"/"+logger+'_info.log', maxBytes=10000000, backupCount=5)
    efh.setLevel(logging.ERROR)
    dfh.setLevel(logging.DEBUG)
    ifh.setLevel(logging.INFO)
    efh.setFormatter(formatter)
    dfh.setFormatter(formatter)
    ifh.setFormatter(formatter)
    log.addHandler(dfh)
    log.addHandler(ifh)
    log.addHandler(efh)
    loggers[logger]=log
    return log
    